import { getAllCatlist } from 'api/playlist'
import { toplist as getToplist } from 'api/toplist'

const state = {
  catlist: [],
  toplist: []
}
const actions = {
  getCatlist() {
    let { catlist } = this.state.discovery
    if (catlist.length === 0) {
      return getAllCatlist().then(res => {
        let sub = res.sub || []
        catlist = sub
        return sub
      })
    }
    return Promise.resolve(catlist)
  },
  getToplist() {
    let { toplist } = this.state.discovery
    if (toplist.length === 0) {
      return getToplist().then(res => {
        let list = res.list || []
        toplist = list
        return list
      })
    }
    return Promise.resolve(toplist)
  }
}
const mutations = {}
const getters = {}

export default {
  state,
  actions,
  mutations,
  getters
}